package com.passive.lock.controller.log;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.passive.lock.model.vo.PageInfo;
import com.passive.lock.model.vo.TSysLogVo;
import com.passive.lock.model.vo.TUserVo;
import com.passive.lock.service.log.SysLogService;
import com.passive.lock.utils.Config;
import com.passive.lock.utils.PageUtil;
import com.passive.lock.utils.ResourcesUtil;
import com.passive.lock.utils.Result;

@Controller
@RequestMapping("sl")
public class SysLogController {
	
	@Autowired
	private SysLogService sysLogService;
	
	@RequestMapping(value = "sysloglist")
	@ResponseBody
	public Result sysLogList(@RequestParam(required = false) long beginTime,
			@RequestParam(required = false) long endTime, @RequestParam(required = false) String logType, @RequestParam(required = false) String username,
			@RequestParam Integer page, @RequestParam Integer limit, HttpServletRequest req, HttpServletResponse resp) {
		TUserVo tUserVo = (TUserVo) req.getSession().getAttribute("tUserVo");
		String groupid= tUserVo.getGroupid();
		try {
			int offset = PageUtil.getOffset(page, limit);
			List<TSysLogVo> list = sysLogService.sysLogList(groupid,beginTime, endTime, logType, username, offset, limit);
			int count = sysLogService.sysLogListCount(groupid,beginTime, endTime, logType, username);
			PageInfo p = new PageInfo();
			p.setLimit(limit);
			p.setPageNum(page);
			p.setTotal(count);
			return new Result(p, list);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.build(500, ResourcesUtil.getValue(Config.MESSAGE, "500"));
		}
	}
}
